import cv2 as cv
import numpy as np
import os
import glob


p = 0
for n in range(1, 200):

    path = r'D:/Users/Ke/Desktop/photoshop/ke2/ke/' + str(n) + '.jpg'
    # 读取图片
    img = cv.imread(path, -1)
    # cv.imshow("img", img)
    # cv.waitKey(0)
    def rotate_img(img, angle):


        h, w = img.shape[:2]
        rotate_center = (w / 2, h / 2)
        M = cv.getRotationMatrix2D(rotate_center, angle, 1.0)
        new_w = int(h * np.abs(M[0, 1]) + w * np.abs(M[0, 0]))
        new_h = int(h * np.abs(M[0, 0]) + w * np.abs(M[0, 1]))

        M[0, 2] += (new_w - w) / 2
        M[1, 2] += (new_h - h) / 2

        rotated_img = cv.warpAffine(img, M, (new_w, new_h))
        return rotated_img


    for i in range(1, 361, 36):
        output_dir = "D:/Users/Ke/Desktop/photoshop/ke2/ke2/"
        image_names = glob.glob("picture/a54sd5a4.jpg")
        rotated_Img = rotate_img(img, i)
        p+=1
        cv.imwrite(os.path.join(output_dir, '%d .jpg' % p), rotated_Img)
